package com.muki.spider.core;

import java.util.ArrayList;
import java.util.List;

public class RequestBuilder {

	private final int default_num = 100;
	private List<RequestUri> requestUris = new ArrayList<>(default_num);
	private static final RequestBuilder container = new RequestBuilder(); 
	
	public static RequestBuilder getInstance() {
		return container;
	}
	
	public RequestBuilder() {
		init();
	}
	
	public void init() {
		for(int i=0;i<default_num;i++) {
			requestUris.add(new RequestUri());
		}
	}

	public RequestUri getRequest() {
		int lastIndex = requestUris.size()-1;
		if(lastIndex>0)
			return requestUris.remove(lastIndex);
		return null;
	}

	public void releaseRequest(RequestUri uri) {
		if(requestUris.size()<default_num)
			requestUris.add(uri);
	}
}
